﻿package mortal.game.view.copy.ChallengeCopy.newView
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.copy.*;
    import mortal.game.view.copy.ChallengeCopy.view.*;
    import mortal.game.view.medal.*;
    import mortal.mvc.core.*;

    public class ChallengeTimePanl3 extends CopyInfoPanelBase
    {
        private var _bgImg:GImageBitmap;
        private var _avatar:GImageBitmap;
        private var _name:GTextFiled;
        private var _combat:BitmapNumberText;
        protected var _minTxt:BitmapNumberText;
        protected var _secTxt:BitmapNumberText;
        protected var _timeTxt:BitmapNumberText;
        protected var _secView:SecTimerView;
        private var _rewardList:Vector.<BaseItem>;
        private var _avatarList:Vector.<AvatarBox>;
        private var _challengeCopyTotalTime:SChallengeCopyTotalTime;
        private var _challengeCopyInfo:TChallengeCopy;
        private var _guideView:ChallengeFightGuide;
        private static var _instance:ChallengeTimePanl3;

        public function ChallengeTimePanl3()
        {
            this._rewardList = new Vector.<BaseItem>;
            this._avatarList = new Vector.<AvatarBox>;
            super(ImagesConst.copyInfoPanelTitle_challengeCopy, 251);
            if (_instance != null)
            {
                throw new Error(" ChallengeTimerPanl3 单例 ");
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bgImg = UIFactory.gImageBitmap(ImagesConst.challengeCopyNewTimerBg_, 0, 0, _bodySprite);
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.challengeCopyNewTxt_1, 19, 224, _bodySprite));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.challengeCopyNewTxt_4, 19, 260, _bodySprite));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.ChallengeNewSugCombatBg, 31, 175, _bodySprite));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.challengeCopyNewTxt_2, 95, 16, _bodySprite));
            var _loc_1:* = GlobalStyle.textFormatHuang2.center();
            _loc_1.size = 14;
            this._name = UIFactory.gTextField("", 0, 51, 251, 25, _bodySprite, _loc_1);
            this._avatar = UIFactory.gImageBitmap("", 96, 93, _bodySprite);
            this._combat = UIFactory.bitmapNumberText(116, 178, "SignUpNum2.png", 22, 23, -6, _bodySprite);
            this._minTxt = UIFactory.bitmapNumberText(31, 308, "ChallengeTimerNum.png", 35, 48, 0, null, 10);
            this._timeTxt = UIFactory.bitmapNumberText(41, 308, "ChallengeTimerNum.png", 35, 48, 0, _bodySprite, 10);
            this._secTxt = UIFactory.bitmapNumberText(171, 308, "ChallengeTimerNum.png", 35, 48, 0, null, 10);
            this._secView = UIFactory.secTimeView("", 0, 0, 0, 0, null);
            this._secView.configEventListener(EventName.SecViewTimeChange, this.onTimeChangeHd);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._bgImg.dispose(param1);
            this._bgImg = null;
            this._name.dispose(param1);
            this._name = null;
            this._avatar.dispose(param1);
            this._avatar = null;
            this._timeTxt.dispose(param1);
            this._timeTxt = null;
            this._minTxt.dispose(param1);
            this._minTxt = null;
            this._secTxt.dispose(param1);
            this._secTxt = null;
            this._combat.dispose(param1);
            this._combat = null;
            if (this._guideView)
            {
                this._guideView.dispose(param1);
                this._guideView = null;
            }
            this._secView.stop();
            this._secView.dispose();
            this._secView = null;
            this.removeRewardItems();
            this.clearAvatarList();
            this._challengeCopyTotalTime = null;
            this._challengeCopyInfo = null;
            Dispatcher.removeEventListener(EventName.ReleaseSkill, this.showTips);
            super.disposeImpl(param1);
            return;
        }// end function

        private function updateRewardList() : void
        {
            var _loc_1:BaseItem = null;
            var _loc_3:Array = null;
            var _loc_4:ItemData = null;
            var _loc_6:int = 0;
            this.removeRewardItems();
            var _loc_2:* = this._challengeCopyInfo.reward.split("&");
            var _loc_5:* = MedalConfig.instance.getTmedalByCode(this._challengeCopyInfo.medalId);
            if (_loc_5)
            {
                _loc_1 = UICompomentPool.getUICompoment(BaseItem);
                _loc_1.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 2);
                var _loc_7:Boolean = false;
                _loc_1.isDropAble = false;
                _loc_1.isDragAble = _loc_7;
                _loc_1.isShowLock = true;
                _loc_1.source = MedalUtil.getMedalIconUrlByTmedal(_loc_5, 0);
                _loc_1.setColorBg(4);
                _bodySprite.addChild(_loc_1);
                this._rewardList.push(_loc_1);
                _loc_1.toolTipData = _loc_5;
            }
            while (_loc_6 < _loc_2.length)
            {
                
                if (_loc_2[_loc_6])
                {
                    _loc_3 = (_loc_2[_loc_6] as String).split("#");
                    _loc_4 = new ItemData(int(_loc_3[0]));
                    if (_loc_4.itemInfo && ItemsUtil.isFitCarrer(_loc_4))
                    {
                        _loc_1 = UICompomentPool.getUICompoment(BaseItem);
                        _loc_1.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 2);
                        var _loc_7:Boolean = false;
                        _loc_1.isDropAble = false;
                        _loc_1.isDragAble = _loc_7;
                        _loc_1.isShowLock = true;
                        _loc_1.itemData = _loc_4;
                        _loc_1.amount = _loc_3[1];
                        _bodySprite.addChild(_loc_1);
                        this._rewardList.push(_loc_1);
                    }
                }
                _loc_6++;
            }
            _loc_6 = 0;
            while (_loc_6 < this._rewardList.length)
            {
                
                this._rewardList[_loc_6].x = _loc_6 * 45 + (265 - 45 * this._rewardList.length) * 0.5;
                this._rewardList[_loc_6].y = 219;
                _loc_6++;
            }
            return;
        }// end function

        private function removeRewardItems() : void
        {
            var _loc_1:BaseItem = null;
            for each (_loc_1 in this._rewardList)
            {
                
                _loc_1.dispose(true);
            }
            this._rewardList.length = 0;
            return;
        }// end function

        private function onTimeChangeHd(event:DataEvent) : void
        {
            if (this._secView == null)
            {
                return;
            }
            if (this._secView.secTimerViewData == null)
            {
                this._secView.stop();
                return;
            }
            var _loc_2:* = this._secView.secTimerViewData.mm();
            var _loc_3:* = this._secView.secTimerViewData.ss();
            this._timeTxt.text = _loc_2 + "(" + _loc_3;
            return;
        }// end function

        protected function setTimeCountDown() : void
        {
            var _loc_1:* = this._challengeCopyTotalTime.totaltime;
            this._secView.stop();
            if (_loc_1 < 0)
            {
                return;
            }
            this._secView.setLeftTime(_loc_1);
            return;
        }// end function

        public function stopCount() : void
        {
            if (this._secView)
            {
                this._secView.stop();
            }
            return;
        }// end function

        public function set data(param1:SChallengeCopyTotalTime) : void
        {
            this._challengeCopyTotalTime = param1;
            this._challengeCopyInfo = ChallengeCopyConfig.instance.challengCopyDic[this._challengeCopyTotalTime.floor][this._challengeCopyTotalTime.level][this._challengeCopyTotalTime.diff];
            this._name.text = this._challengeCopyInfo.levelName;
            this._combat.text = this._challengeCopyInfo.sugCombat.toString();
            this.updateRewardList();
            this.setTimeCountDown();
            this.createBossAvatars();
            if (this._challengeCopyInfo.tower == this._challengeCopyInfo.section == 1 && this._challengeCopyInfo.level == 7)
            {
                Dispatcher.addEventListener(EventName.ReleaseSkill, this.showTips);
            }
            return;
        }// end function

        private function createBossAvatars() : void
        {
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            var _loc_4:AvatarBox = null;
            this.clearAvatarList();
            var _loc_1:* = this._challengeCopyInfo.bossId.split("#");
            if (_loc_1.length > 1)
            {
                this._bgImg.imgUrl = ImagesConst.challengeCopyNewTimerBg_2;
            }
            else
            {
                this._bgImg.imgUrl = ImagesConst.challengeCopyNewTimerBg_;
            }
            while (_loc_2 < _loc_1.length)
            {
                
                _loc_3 = int(_loc_1[_loc_2]);
                _loc_4 = UICompomentPool.getUICompoment(AvatarBox);
                _loc_4.bgUrl = ImagesConst.challengeAvatarBg_;
                _loc_4.avatarUrl = BossConfig.instance.getInfoByCode(_loc_3).avatarId + ".png";
                _bodySprite.addChild(_loc_4);
                _loc_4.x = (this.width - _loc_1.length * 75) * 0.5 + 75 * _loc_2 - 5;
                _loc_4.y = 88;
                this._avatarList.push(_loc_4);
                _loc_2++;
            }
            return;
        }// end function

        private function clearAvatarList() : void
        {
            var _loc_1:AvatarBox = null;
            for each (_loc_1 in this._avatarList)
            {
                
                _loc_1.dispose();
            }
            this._avatarList.length = 0;
            return;
        }// end function

        private function showTips(event:DataEvent) : void
        {
            if (this._challengeCopyInfo.tower == this._challengeCopyInfo.section == 1 && this._challengeCopyInfo.level == 7 && event.data as int == 51430061)
            {
                if (this._guideView == null)
                {
                    this._guideView = UICompomentPool.getUICompoment(ChallengeFightGuide);
                }
                this._guideView.show();
            }
            return;
        }// end function

        public static function get instance() : ChallengeTimePanl3
        {
            if (_instance == null)
            {
                _instance = new ChallengeTimePanl3;
            }
            return _instance;
        }// end function

        public static function get isViewShow() : Boolean
        {
            return _instance && !_instance.isHide;
        }// end function

    }
}
